package com.zyiot.adapter;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.zyiot.lbs.R;

public class MessagesAdapter extends BaseAdapter {
	private List<HashMap<String, Object>> items;
	private LayoutInflater mInflater;
	private Context context;

	/* class ViewHolder */
	private class ViewHolder {
		TextView msg_title;
		TextView msg_content;
		TextView msg_date;
		CheckBox msg_cb_delete;
	}

	public MessagesAdapter(Context context, List<HashMap<String, Object>> list) {
		this.context = context;
		mInflater = LayoutInflater.from(context);
		items = list;
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;

		if (convertView == null) {
			// 获得ViewHolder对象
			holder = new ViewHolder();
			// 导入布局并赋值给convertview
			convertView = mInflater.inflate(R.layout.content_message, null);
			holder.msg_title = (TextView) convertView.findViewById(R.id.msg_title);
			holder.msg_content = (TextView) convertView.findViewById(R.id.msg_content);
			holder.msg_date = (TextView) convertView.findViewById(R.id.msg_date);
//			holder.msg_cb_delete = (CheckBox) convertView.findViewById(R.id.msg_cb_select);
			// 为view设置标签
			convertView.setTag(holder);

		} else {

			// 取出holder
			holder = (ViewHolder) convertView.getTag();
		}

		// 设置list中TextView的显示

		holder.msg_title.setText(items.get(position).get("msg_title").toString());
		holder.msg_content.setText(items.get(position).get("msg_content").toString());
		holder.msg_date.setText(items.get(position).get("msg_date").toString());

		// 根据flag来设置checkbox的选中状况
		//holder.msg_cb_delete.setChecked(items.get(position).get("msg_flag").equals("true"));
		return convertView;

	}

}
